package com.example.happiness.controller.user;

import com.example.happiness.constant.Message;
import com.example.happiness.pojo.Order;
import com.example.happiness.pojo.generalDTO.OrderStateDTO;
import com.example.happiness.pojo.uservo.UserOrderVO;
import com.example.happiness.result.Result;
import com.example.happiness.service.user.UserOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "订单接口")
@Slf4j
@RestController
@RequestMapping("/user/order")
public class UserOrderController {

    @Autowired
    UserOrderService userOrderService;

    @PostMapping("/addorder")
    @ApiOperation("添加订单")
    public Result<String> addorder(@RequestBody Order order) {
        userOrderService.addorder(order);
        return Result.success(order.getOrderid());
    }

    @GetMapping("/getuserorders")
    @ApiOperation("获取用户订单")
    public Result<List<UserOrderVO>> getuserorders(String userid){
        return Result.success(userOrderService.getuserorders(userid));
    }

    @PostMapping("/updataorderstate")
    @ApiOperation("修改订单状态")
    public Result updataOrderState(@RequestBody OrderStateDTO orderStateDTO){
        orderStateDTO.setState(Message.FIVE);
        userOrderService.updataOrderState(orderStateDTO);
        return Result.success();
    }
}
